<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 400px;
            height: 50px;
            background-color: antiquewhite;
            text-align: center;
            line-height: 50px;
        }
    </style>
</head>

<body>
    <button> 显示当前时间</button>
    <div>
        某个时间
    </div>
    <script>
        var btn = document.querySelector('button');
        var div = document.querySelector('div');

        function getCurrentTime() {
            var now = new Date();
            var hours = now.getHours();
            var minutes = now.getMinutes();
            var seconds = now.getSeconds();

            hours = hours < 10 ? '0' + hours : hours;
            minutes = minutes < 10 ? '0' + minutes : minutes;
            seconds = seconds < 10 ? '0' + seconds : seconds;

            return hours + ':' + minutes + ':' + seconds;
        }

        function xs() {
            div.innerHTML = getCurrentTime();
        }

        btn.addEventListener('click', function() {
            xs();
            setInterval(xs, 1000);
        });
    </script>
</body>

</html>